<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="initial-scale=1.0, user-scalable=no, width=device-width"
    />
    <title>HELLO，AMAP!</title>
    <style>
      html,
      body,
      #container {
        width: 100%;
        height: 100%;
      }
    </style>
    <script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode: "21e81db676a76ade4fb1c8c10f1ff377"
        };
        // 声明异步加载回调函数
        window.onLoad = function(){
            var map = new AMap.Map("container"); // container为div容器的id
        };
        var url = "https://webapi.amap.com/maps?v=2.0&key=879ec191ca2bb6c8ee0a3844aa9b5358&callback=onLoad";
        var jsapi = document.createElement("script");
        jsapi.charset = "utf-8";
        jsapi.src =  url;
        document.head.appendChild(jsapi);
    </script>
    <script src="https://webapi.amap.com/loader.js"></script>
    <script type="text/javascript">
        AmapLoader.load({
            key:"879ec191ca2bb6c8ee0a3844aa9b5358",
            version:"2.0"
        }).then((AMap)=>{
            const map = new AMap.Map("container");
            const marker = new AMap.Marker({
                position:[116.397428, 39.90923] // 位置
            });
            map.add(marker); // 添加到地图
        }).catch((e)=>{
            console.log(e);
        })
    </script>
  </head>
  <body>
    <div id="container"></div>
  </body>
</html>